import bt from '../../assets/images/bt.jpg';
import img from '../../assets/images/img.jpg';
import music from '../../assets/images/music.jpg';
import txt from '../../assets/images/txt.jpg';
import unkown from '../../assets/images/unkown.jpg';
import video from '../../assets/images/video.jpg';
import zip from '../../assets/images/zip.jpg';
import dir from '../../assets/images/dir.jpg';


Component({
  name: 'imgItem',
  props: {
    // 这里定义了innerText属性，属性值可以在组件使用时指定
    fileName: {
      type: String,
      value: 'unkown',
    },
    isDir: {
      type: Boolean,
      value: false
    },
    content: {
      type: Object,
      value: {}
    }
  },
  data() {
    return {
      imageType: ['png', 'PNG', 'jpg', "JPG", 'JPEG', 'jpeg', 'GIF', 'gif', 'SVG', 'svg', 'webp', 'bmp'],
      videoType: ['MP4', 'mp4', 'mov', 'MOV', 'flv', 'm2v', 'mkv', 'rmvb', 'wmv', 'avi', 'flv', 'm4v', 'MKV'],
      bt,
      img,
      music,
      txt,
      unkown,
      video,
      zip,
      dir,
      urlImg: unkown,
    };
  },
  methods: {
    getIcon(name) {
      if (!name) return this.unkown
      const typeName = name.split('.').reverse()[0]
      if (this.imageType.includes(typeName)) {
        return this.img
      } else if (this.videoType.includes(typeName)) {
        return this.video
      } else if ([, 'MP3', 'mp3', 'wav', 'flac', 'aac', 'mid'].includes(typeName)) {
        return this.music
      } else if (['txt', 'html', 'rtf', 'log', 'csv'].includes(typeName)) {
        return this.txt
      } else if (['rar', 'zip'].includes(typeName)) {
        return this.zip
      } else if (['torrent'].includes(typeName)) {
        return this.bt
      } else {
        return this.unkown
      }
    }
  },
  mounted() {
    if (this.isDir) {
      this.urlImg = this.dir
    } else {
      if(this.content && this.content.thumbnail){
        this.urlImg = this.content.thumbnail
      }else{
        this.urlImg = this.getIcon(this.fileName)
      }
      
    }
  }
});
